// $Id: wchar.hpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2008-2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

//
// Some of following code is copied from boost/integer_traits.hpp
// Should keep it update...
//

#include <climits>

#ifndef BOOST_NO_CWCHAR
#include <cwchar> // for WCHAR_MIN and WCHAR_MAX
#endif

// We need wchar.h for WCHAR_MAX/MIN but not all platforms provide it,
// and some may have <wchar.h> but not <cwchar> ...
#if !defined(BOOST_NO_CWCHAR) || defined(sun) || defined(__sun) || defined(__QNX__)
#include <wchar.h>
#endif

// Workaround for MSVC < 8.0, where the WCHAR_MAX is badly defined
#if defined(_MSC_VER) && _MSC_VER < 1400
#  define XPCOM_HAS_2BYTE_WCHAR_T

#elif defined(WCHAR_MIN) && defined(WCHAR_MAX) && !defined(__APPLE__)
#  if WCHAR_MAX == 0xFFFF || WCHAR_MAX == 32767
#    define XPCOM_HAS_2BYTE_WCHAR_T
#  elif WCHAR_MAX == 0xFFFFFFFF || WCHAR_MAX == 2147483647
#    define XPCOM_HAS_4BYTE_WCHAR_T
#  endif

#elif defined(__BORLANDC__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__BEOS__) && defined(__GNUC__))
   // No WCHAR_MIN and WCHAR_MAX, whar_t is short and unsigned:
#  define XPCOM_HAS_2BYTE_WCHAR_T

#elif (defined(__sgi) && (!defined(__SGI_STL_PORT) || __SGI_STL_PORT < 0x400)) \
   || (defined __APPLE__)\
   || (defined(__OpenBSD__) && defined(__GNUC__))\
   || (defined(__NetBSD__) && defined(__GNUC__))\
   || (defined(__FreeBSD__) && defined(__GNUC__))\
   || (defined(__DragonFly__) && defined(__GNUC__))\
   || (defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 3) && !defined(__SGI_STL_PORT))
   // No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as int.
   //  - SGI MIPSpro with native library
   //  - gcc 3.x on HP-UX
   //  - Mac OS X with native library
   //  - gcc on FreeBSD, OpenBSD and NetBSD
#  if INT_MAX == 32767
#    define XPCOM_HAS_2BYTE_WCHAR_T
#  elif INT_MAX == 2147483647
#    define XPCOM_HAS_4BYTE_WCHAR_T
#  endif

#elif defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 2) && !defined(__SGI_STL_PORT)
   // No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as unsigned int.
   //  - gcc 2.95.x on HP-UX
#  if UINT_MAX == 0xFFFF
#    define XPCOM_HAS_2BYTE_WCHAR_T
#  elif UINT_MAX == 0xFFFFFFFF
#    define XPCOM_HAS_4BYTE_WCHAR_T
#  endif

#else
#  error no WCHAR_MIN and WCHAR_MAX present, please adjust for your compiler.
#endif
